layui.use(['layer', 'form', 'table', 'admin', 'ax', 'func'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;

    /**
     * 系统管理--消息管理
     */
    var Notice = {
        tableId: "noticeTable"    //表格id
    };
    $("#condition").on("input",function(e){
        //获取input输入的值
        Notice.search();
    });

    $("#ghs").on("input",function(e){
        //获取input输入的值
        Notice.search();
    });
    /**
     * 选中行效果
     */
    table.on('row(noticeTable)',function(obj){
        $(obj.tr).siblings().css("background-color","");
        obj.tr.css({"background-color":"#dadad9"});
    });
    /**
     * 检索店名
     */
    var languageAjax = new $ax(Feng.ctxPath + "/btyBxda/getDm");
    var languageResult = languageAjax.start();
    console.info(languageResult);
    $.each(languageResult, function( index, val ) {
        $("#dm").append("<option value='"+val.dm+"'>"+val.dm+"</option>");
    } );
    form.render('select');
    /**
     * 初始化表格的列
     */
    Notice.initColumn = function () {
        return [[
            {type: 'checkbox',hide: true,},
            {field: 'id', align: "center", hide: true, sort: true, title: 'id',},
             {align: 'center', type: "numbers", title: '序号'},
            {field: 'provinceName', align: "center",title: '省份',width:150},
            {field: 'num', align: "center",sort:true, title: '数量',width:100,totalRow: true},
            {field: 'name', align: "left", title: '店名', style:'', templet: function (d) {
                    if (d.name.indexOf("|")!=-1) {
                        let str=d.name.split("|");
                        let div="<div style=\"overflow: auto;text-overflow: unset;white-space: break-spaces;\">";
                        for (let i = 0; i <str.length ; i++) {
                            div += "<span style='margin-right: 10px; margin-bottom: 5px;'>" + str[i] + "</span>";
                          }
                        div+="</div>";
                       return div;

                    } else {
                        return "<div  >" +
                            "<span>"+d.name+"</span>" +
                            '</div>';
                        //return '<div class="show_img"><img  src="'+d.picture+'" alt="" width="100px" height="100px"></div>';
                    }
                }},
            //{align: 'center', toolbar: '#tableBar', title: '店名', align: "center", width: 600},

        ]];
    };

    /**
     * 点击查询按钮
     */
    Notice.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        queryData['ghs'] = $("#ghs").val();
        queryData['status'] = $("#status").val();
        queryData['dm'] = $("#dm").val();
        table.reload(Notice.tableId, {
            where: queryData, page: {curr: 1}
        });
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + Notice.tableId,
        url: Feng.ctxPath + '/project/projectList',
        page: true,
        height: "full-98",
        cellMinWidth: 100,
        even: true,
        limit: 20,
        totalRow: true,	//开启合计行
        ///skin: 'line',
        cols: Notice.initColumn(),
        // done:function (res, curr, count) {
        //     //图片预览
        //     layer.photos({
        //         photos: '.show_img',
        //         anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
        //     });
        // }
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        Notice.search();
    });

    // 添加按钮点击事件
    $('#btnAdd').click(function () {
        Notice.openAddNotice();
    });

    // 识别行号按钮点击事件
    $('#btnSbhh').click(function () {
        Notice.btnSbhhNotice();
    });


    // 工具条点击事件
    table.on('tool(' + Notice.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
            Notice.onEditNotice(data);
        } else if (layEvent === 'delete') {
            Notice.onDeleteNotice(data);
        }else if (layEvent === 'editKj') {
            Notice.onEditKj(data);
        }
    });

    $('#btnExport').click(function(){
        window.location.href=Feng.ctxPath+'/project/areaSummaryExport';
    });
});
